package sy10_3;

import java.sql.SQLOutput;

public class Tickets {
    public static void main(String[] args) {
        SellTickets st=new SellTickets();
        Thread Wdons1=new Thread( st,"售票口1");
        Thread Wdons2=new Thread( st,"售票口2");
        Thread Wdons3=new Thread( st,"售票口3");
        Wdons1.start();
        Wdons3.start();
        Wdons2.start();
    }


}
class SellTickets implements Runnable{
    private int tickets=10;
    private int n=0;
    Object obj=new Object();
    @Override
    public void run() {
        while (true){
            synchronized (obj){
                if(n<tickets){
                    System.out.printf("%s正在销售第%d张票。\n",Thread.currentThread().getName(),n+1);
                    n++;
                }else {
                    System.exit(0);
                }
                try{
                    Thread.sleep(100);
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
            }
        }
    }
}
